package com.tiantianyuegou.util;

import android.annotation.TargetApi;
import android.app.Activity;
import android.os.Build;
import android.support.v4.content.ContextCompat;
import android.view.Window;
import android.view.WindowManager;

import com.tiantianyuegou.R;

/**
 * Created by George on 2016/8/31.
 */
public class Tools {
    public static void changeSystemBar(Activity activity){
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            setTranslucentStatus(true,activity);
            SystemBarTintManager tintManager = new SystemBarTintManager(activity);
            tintManager.setStatusBarTintEnabled(true);
            tintManager.setNavigationBarTintEnabled(true);
            tintManager.setStatusBarTintColor(ContextCompat.getColor(activity, R.color.bg_button_normal));
            tintManager.setNavigationBarTintResource(R.color.bg_button_normal);
            tintManager.setStatusBarTintDrawable(activity.getResources()
                    .getDrawable(R.color.bg_button_normal));

        }
    }
    @TargetApi(19)
    private static void setTranslucentStatus(boolean on, Activity activity) {
        // TODO Auto-generated method stub
        Window win = activity.getWindow();
        WindowManager.LayoutParams winParams = win.getAttributes();
        final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
        if (on) {
            winParams.flags |= bits;
        } else {
            winParams.flags &= ~bits;
        }
        win.setAttributes(winParams);
    }


}
